/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.client.control;


import com.edu.kamai.webservice.client.WSUserAccountClient;
import com.edu.kamai.webservice.user.User;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class usrControl {
    private static List<String> netList;
    private static String message;
    private static WSUserAccountClient wsUserAccoutnClient;
    
    public static String getMessage() {
        return message;
    }

    public static void setMessage(String message) {
        usrControl.message = message;
    }
    
    public static void setServer(){
        try{
            wsUserAccoutnClient = new WSUserAccountClient();
            
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static List<String> getNetList() {
        return netList;
    }

    public static void setNetList(List<String> l) {
        netList = l;
    }
    
    public static int register(String usrID,String usrPwd,String Email,int role){
        int ans;
        try{
            ans = wsUserAccoutnClient.register(usrID, usrPwd, Email, role);
            if (ans == 1) {
                message = "Register OK!";
            } else {
                message = "Register Failed!";
            }

        }catch(Exception ex){
            ans = 0;
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return ans;
    }
    
    public static int login(String usrID,String usrPwd,int role){
        int ans;
        try{
            ans = wsUserAccoutnClient.login(usrID, usrPwd, role);
            if(ans == 1){
                message = "Login Successfully!";
            }else{
                message = "Login Failed!";
            }
        }catch(Exception ex){
            ans = 0;
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return ans;
    }
    
    public static int validateUsr(String usrID){
        int ans;
        try{
            ans = wsUserAccoutnClient.validateUsr(usrID);
            if(ans == 1){
                message = "Validate Successfully!";
            }else{
                message = "Validate Failed!";
            }
        }catch(Exception ex){
                ans = 0;
                message = "Connect Server Error!";
                ex.printStackTrace();
            }
        return ans;
    }
    
    
    public static List<User> chekPendingList(){
        List<User> pending=null;
        try{
            pending = wsUserAccoutnClient.chekPendingList();
            if(pending.size() == 0){
                message = "no new users!";
            }else{
                message = "new users are coming!";
            }
        }catch(Exception ex){
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return pending;
    }
}
